# -*- coding: utf-8 -*-
'''
Created on 2021-1-8

@author: qqyu
'''

from datetime import datetime
import time

def str_to_millisecond(format_time):
    # format_time = '2017-03-16'# 00:00:00
    if ':' in format_time:
        ts = time.strptime(format_time.replace('-','/'), "%Y/%m/%d %H:%M:%S")# %H:%M:%S
    else:
        ts = time.strptime(format_time.replace('-','/')+' 23:59:59', "%Y/%m/%d %H:%M:%S")# %H:%M:%S
    return str(int(time.mktime(ts)*1000))

def is_current_year_month(data_str):
    t = datetime.now()
    currentMillion = str_to_millisecond('{year}/{month}/01'.format(year=t.year,month=t.month))
    try:
        year,month = data_str.replace('/','-').split('-')[0:-1]
    except Exception as err:
        print('出现错误==>',data_str,err.args)
        year,month = '2020','10'
    injobMillion = str_to_millisecond('{year}/{month}/01'.format(year=year,month=month))
    return (currentMillion==injobMillion and '是') or '否'

def millo_to_yearmonthday(timestamp):
    timestamp = int(timestamp)
    # timestamp = 1608739200000
    #             1610622596000
    time_local = time.localtime(timestamp/1000)
    dt = time.strftime("%Y/%m/%d", time_local)
    return dt # 2019-10-11 14:15:56

